import java.util.Scanner;

/**
 * 提供先序遍历的字符串创建二叉树
 * 使用中序遍历打印二叉树的值
 */
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    private static class TreeNode {
        private char val;
        private TreeNode left = null;
        private TreeNode right = null;
        public TreeNode(char val) {
            this.val = val;
        }
    }
    private static int index = 0;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            index = 0;
            TreeNode root = creatTree(s);
            midOrder(root);
            System.out.println();
        }
    }

    private static TreeNode creatTree(String s) {
        char val = s.charAt(index);
        index++;
        if(val == '#') {
            return null;
        }
        TreeNode root = new TreeNode(val);
        root.left = creatTree(s);
        root.right = creatTree(s);
        return root;
    }

    private static void midOrder(TreeNode root) {
        if(root == null) {
            return;
        }
        midOrder(root.left);
        System.out.print(root.val + " ");
        midOrder(root.right);
    }
}